package com.socket;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

/**
 * @author Yancy
 * @program springioctest
 * @create 2021-01-17
 */
public class TestInetSocketAddress {

  public static void main(String[] args) throws UnknownHostException {
    //
      //本机主机名和ip地址
      InetAddress ia = InetAddress.getLocalHost();
    System.out.println(ia.toString());
    //ip地址
    System.out.println(ia.getHostAddress());
    //本机名
    System.out.println(ia.getHostName());

    System.out.println(ia.getAddress());

    InetAddress iaStr = InetAddress.getByName("www.baidu.com");
    System.out.println(iaStr.toString());

    //ip+端口
      InetSocketAddress isa = new InetSocketAddress(ia,8888);
      //主机名和ip地址
    System.out.println(isa.getAddress());
    // ip
    System.out.println(isa.getAddress().getHostAddress());
    // 主机名
    System.out.println(isa.getAddress().getHostName());
  }
}
